package o;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import o.dky.j;

public class evr {
    private static evr ˊ;
    private static int ˋ = -100;
    private List<evn> ʼ = new ArrayList();
    private Handler ʽ = new Handler();
    private int ˎ = 0;
    private String ˏ = null;
    private evu ॱ = new evu();
    private View ॱॱ = null;
    private evn ᐝ;

    static class b implements Runnable {
        private WeakReference<ViewGroup> ˊ;

        public b(ViewGroup viewGroup) {
            this.ˊ = new WeakReference(viewGroup);
        }

        public void run() {
            ViewGroup viewGroup = (ViewGroup) this.ˊ.get();
            if (viewGroup != null) {
                evr.ˊ().ˎ(viewGroup);
            }
        }
    }

    private evr() {
    }

    public static void ˊ(int i) {
        ˋ = i;
    }

    public static synchronized evr ˊ() {
        evr o_evr;
        synchronized (evr.class) {
            if (ˊ == null) {
                ˊ = new evr();
            }
            o_evr = ˊ;
        }
        return o_evr;
    }

    public static boolean ˏ() {
        if (ˋ == -100) {
            ˊ(ˊ().ˋ());
        }
        if (ˋ == 2) {
            Logger.ˏ("VideoPlayManager", "close auto play");
            return false;
        } else if ((ˋ != 1 || VideoNetChangeDialog.ˎ(ContentManager.getInstant().getContext())) && evt.ˎ() > 30) {
            return true;
        } else {
            return false;
        }
    }

    public static void ˏ(Context context) {
        if (context != null) {
            Intent intent = new Intent();
            intent.setAction("com.huawei.appmarket.video.refresh.action");
            ll.ˏ(context).ˋ(intent);
        }
    }

    public void ˎ(String str, int i) {
        if (this.ॱ == null) {
            this.ॱ = new evu();
        }
        this.ॱ.ॱ(str);
        this.ॱ.ˎ(i);
        if (i == 7) {
            this.ˏ = str;
            if (this.ᐝ != null) {
                this.ॱॱ = this.ᐝ.ˋᐝ();
            }
        }
    }

    public int ˋ() {
        return eua.ˏ().ॱ("video_setting_status", 1);
    }

    public void ˋ(int i) {
        eua.ˏ().ˊ("video_setting_status", i);
        ˊ(i);
        this.ॱ.ॱ(null);
        this.ॱ.ˎ(0);
    }

    public evn ˏ(int i) {
        if (i >= this.ʼ.size() || i < 0) {
            return null;
        }
        return (evn) this.ʼ.get(i);
    }

    public evn ˎ() {
        return this.ᐝ;
    }

    public void ˏ(evn o_evn) {
        if (this.ᐝ != o_evn) {
            ॱॱ();
            this.ᐝ = o_evn;
            this.ˎ = this.ʼ.indexOf(this.ᐝ);
        }
    }

    public void ॱ() {
        if (this.ᐝ == null) {
            return;
        }
        if (this.ᐝ.ʻॱ() || this.ᐝ.ॱˎ()) {
            this.ᐝ.ॱˊ();
        }
    }

    public void ʻ() {
        if (this.ᐝ == null) {
            return;
        }
        if ((this.ᐝ.ʻॱ() || this.ᐝ.ॱˎ()) && this.ᐝ.ʼॱ()) {
            this.ᐝ.ॱˊ();
        }
    }

    private void ˏॱ() {
        if (!(TextUtils.isEmpty(this.ˏ) && this.ॱॱ == null) && evt.ˊ(this.ॱॱ) < 50) {
            this.ˏ = null;
            this.ॱॱ = null;
        }
    }

    public void ᐝ() {
        this.ˏ = null;
        this.ॱॱ = null;
        ॱॱ();
        if (this.ᐝ == null || !this.ᐝ.ʼॱ()) {
            this.ʼ.clear();
        }
    }

    public void ॱॱ() {
        ˏॱ();
        if (this.ᐝ != null && !this.ᐝ.ʼॱ()) {
            this.ॱ.ॱ(null);
            this.ॱ.ˎ(0);
            this.ᐝ.ˍ();
            this.ᐝ = null;
        }
    }

    private void ˊॱ() {
        if (this.ᐝ != null) {
            this.ᐝ.ˍ();
            this.ᐝ = null;
        }
    }

    public boolean ʽ() {
        if (this.ᐝ == null || !this.ᐝ.ʼॱ()) {
            return false;
        }
        return this.ᐝ.ˊ();
    }

    public void ʼ() {
        if (!CollectCheck.isEmpty(this.ʼ) && ˋ != 2) {
            Context ˋ = ContentManager.getInstant().getContext();
            if ((ˋ != 1 || VideoNetChangeDialog.ˎ(ˋ)) && evt.ˎ() > 30) {
                this.ˎ++;
                evn ˏ = ˏ(this.ˎ);
                if (ˏ == null) {
                    ॱॱ();
                    return;
                }
                ˏ.ʽ();
                this.ˏ = null;
                this.ॱॱ = null;
            }
        }
    }

    public void ॱ(int i) {
        switch (i) {
            case 1:
            case 2:
                ˏॱ();
                if (this.ᐝ != null && evt.ˊ(this.ᐝ.ˋᐝ()) < 50) {
                    ॱॱ();
                    return;
                }
                return;
            default:
                return;
        }
    }

    public boolean ˊ(ViewGroup viewGroup) {
        if (!ˏ(viewGroup)) {
            return false;
        }
        List arrayList = new ArrayList();
        List arrayList2 = new ArrayList();
        ˎ(viewGroup, arrayList, ContentManager.getInstant().getContext().getString(j.ꓸ));
        if (CollectCheck.isEmpty(arrayList)) {
            return false;
        }
        int i = 0;
        while (i < arrayList.size()) {
            if (evt.ˊ((View) arrayList.get(i)) >= 50 && (arrayList.get(i) instanceof evn)) {
                evn o_evn = (evn) arrayList.get(i);
                if (!TextUtils.isEmpty(o_evn.ॱ())) {
                    arrayList2.add(o_evn);
                }
            }
            i++;
        }
        if (CollectCheck.isEmpty(arrayList2)) {
            return false;
        }
        return true;
    }

    public void ˎ(ViewGroup viewGroup) {
        if ((this.ᐝ == null || !this.ᐝ.ʼॱ()) && ˏ(viewGroup)) {
            List arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            Context ˋ = ContentManager.getInstant().getContext();
            ˎ(viewGroup, arrayList, ˋ.getString(j.ꓸ));
            if (CollectCheck.isEmpty(arrayList)) {
                ʻॱ();
                this.ʼ.clear();
                ˊॱ();
                return;
            }
            int i = 0;
            while (i < arrayList.size()) {
                if (evt.ˊ((View) arrayList.get(i)) >= 50 && (arrayList.get(i) instanceof evn)) {
                    evn o_evn = (evn) arrayList.get(i);
                    if (!TextUtils.isEmpty(o_evn.ॱ())) {
                        arrayList2.add(o_evn);
                    }
                }
                i++;
            }
            if (CollectCheck.isEmpty((List) arrayList2)) {
                ʻॱ();
                this.ʼ.clear();
                ˊॱ();
                return;
            }
            Logger.ˏ("getAllPlayerView", "realVideoPlayersSize: " + arrayList2.size());
            if (this.ᐝ == null) {
                if (Logger.ˎ()) {
                    Logger.ˏ("getAllPlayerView", "no video play,playerIndex: " + this.ˎ + ",realVideoPlayersSize: " + arrayList2.size());
                }
                this.ˎ = 0;
                ʻॱ();
                ˊॱ();
                this.ʼ.clear();
                this.ʼ.addAll(arrayList2);
            } else if (ˎ(arrayList2)) {
                ʻॱ();
                this.ʼ.clear();
                this.ʼ.addAll(arrayList2);
                this.ˎ = this.ʼ.indexOf(this.ᐝ);
                Logger.ˏ("getAllPlayerView", "realVideoPlayers.contains(mVideoPlayer),playerIndex: " + this.ˎ);
                return;
            } else {
                Logger.ˏ("getAllPlayerView", "is play but is not in the list,playerIndex: " + this.ˎ);
                ʻॱ();
                this.ʼ.clear();
                this.ʼ.addAll(arrayList2);
                ˊॱ();
                this.ˎ = 0;
            }
            ॱᐝ();
            ˋ(ˋ);
        }
    }

    private boolean ˎ(ArrayList<evn> arrayList) {
        return ˊ(arrayList, this.ᐝ) && (this.ᐝ.ʻॱ() || this.ᐝ.ॱˎ());
    }

    private void ˎ(ViewGroup viewGroup, ArrayList<View> arrayList, String str) {
        if (viewGroup != null && arrayList != null && !TextUtils.isEmpty(str)) {
            int childCount = viewGroup.getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (str.equals(viewGroup.getChildAt(i).getTag())) {
                    arrayList.add(viewGroup.getChildAt(i));
                }
                if (viewGroup.getChildAt(i) instanceof ViewGroup) {
                    ˎ((ViewGroup) viewGroup.getChildAt(i), arrayList, str);
                }
            }
        }
    }

    private void ˋ(Context context) {
        if (evt.ˎ() > 30 || ॱˋ()) {
            evn ˏ = ˏ(this.ˎ);
            if (ˏ != null && ॱ(context, ˏ.ॱ())) {
                ˏ.ʽ();
                this.ˏ = null;
                this.ॱॱ = null;
            }
        }
    }

    private void ॱˊ() {
        if (!TextUtils.isEmpty(this.ˏ)) {
            int i = 0;
            while (i < this.ʼ.size()) {
                if (this.ˏ.equals(((evn) this.ʼ.get(i)).ॱ())) {
                    break;
                }
                i++;
            }
            i = -100;
            if (i >= 0 && this.ˎ == i) {
                this.ˎ++;
            }
        }
    }

    private void ॱᐝ() {
        if (this.ॱ != null) {
            if (!TextUtils.isEmpty(this.ॱ.ˎ())) {
                int i;
                String ˎ = this.ॱ.ˎ();
                int ˊ = this.ॱ.ˊ();
                for (int i2 = 0; i2 < this.ʼ.size(); i2++) {
                    if (ˎ.equals(((evn) this.ʼ.get(i2)).ॱ())) {
                        i = i2;
                        break;
                    }
                }
                i = -100;
                if (ˊ == 7) {
                    i++;
                }
                if (i >= 0 && i < this.ʼ.size()) {
                    this.ˎ = i;
                }
            }
            ॱˊ();
        }
    }

    private boolean ˏ(ViewGroup viewGroup) {
        if (viewGroup == null || evt.ˊ((View) viewGroup) < 50 || epi.ˏ().ˋ() || !doo.ˊ(viewGroup.getContext())) {
            return false;
        }
        if (ˋ == -100) {
            ˊ(ˊ().ˋ());
        }
        if (ˋ == 2) {
            Logger.ˏ("VideoPlayManager", "close auto play");
            if (ॱˋ()) {
                return true;
            }
            return false;
        } else if (ˋ != 1 || VideoNetChangeDialog.ˎ(viewGroup.getContext())) {
            return true;
        } else {
            if (ॱˋ()) {
                return true;
            }
            Logger.ˏ("VideoPlayManager", "auto play only wifi but now is mobile network");
            return false;
        }
    }

    private boolean ॱ(Context context, String str) {
        if (this.ॱ == null) {
            return true;
        }
        if (ˋ != 2 && (ˋ != 1 || VideoNetChangeDialog.ˎ(context))) {
            return true;
        }
        Object ˎ = this.ॱ.ˎ();
        if (TextUtils.isEmpty(ˎ)) {
            return false;
        }
        if (ˎ.equals(str)) {
            this.ॱ.ॱ(null);
            this.ॱ.ˎ(0);
            return true;
        }
        this.ॱ.ॱ(null);
        this.ॱ.ˎ(0);
        return false;
    }

    private boolean ॱˋ() {
        if (this.ॱ == null) {
            return false;
        }
        CharSequence ˎ = this.ॱ.ˎ();
        int ˊ = this.ॱ.ˊ();
        if (TextUtils.isEmpty(ˎ) || ˊ == 0) {
            return false;
        }
        return true;
    }

    private boolean ˊ(ArrayList<evn> arrayList, evn o_evn) {
        if (o_evn == null) {
            return false;
        }
        if (evt.ˊ(o_evn.ˋᐝ()) < 50) {
            return false;
        }
        if (arrayList.contains(o_evn)) {
            return ((evn) arrayList.get(arrayList.indexOf(o_evn))).ॱ().equals(o_evn.ॱ());
        } else {
            return false;
        }
    }

    private void ʻॱ() {
        for (int i = 0; i < this.ʼ.size(); i++) {
            evn o_evn = (evn) this.ʼ.get(i);
            if (!(o_evn == null || this.ᐝ == o_evn)) {
                o_evn.ˍ();
            }
        }
    }

    public void ˋॱ() {
        ʻॱ();
        this.ʼ.clear();
        this.ˎ = 0;
        ॱॱ();
    }

    public void ͺ() {
        evt.ˏ();
        evt.ॱ();
        ʻॱ();
        this.ʼ.clear();
        this.ˎ = 0;
        ॱॱ();
        this.ॱ.ॱ(null);
        this.ॱ.ˎ(0);
    }

    public void ˋ(ViewGroup viewGroup) {
        this.ʽ.postDelayed(new b(viewGroup), 500);
    }
}
